Skip to content

test(webhooks): hoist delivery route mocks#368

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
Zekbot001:money/ugig-webhook-test-hoist
Jun 4, 2026
Merged

test(webhooks): hoist delivery route mocks#368
ralyodio merged 1 commit into
profullstack:masterfrom
Zekbot001:money/ugig-webhook-test-hoist

Conversation

@Zekbot001
Copy link
Copy Markdown
Contributor

Summary

  • initialize webhook-deliveries route mocks with vi.hoisted()
  • fix the Vitest temporal-dead-zone failure introduced with the pagination coverage
  • restore execution of all four delivery pagination regression tests

Paid task

https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e

Verification

  • pnpm exec vitest run 'src/app/api/webhooks/[id]/deliveries/route.test.ts'
  • pnpm exec eslint 'src/app/api/webhooks/[id]/deliveries/route.test.ts'
  • git diff --check

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 31, 2026

Greptile Summary

This PR fixes a Vitest temporal dead zone (TDZ) failure in the webhook deliveries route test by wrapping the top-level mock function declarations with vi.hoisted(), ensuring they are initialized during Vitest's hoist phase — before vi.mock() factory functions execute.

  • mockFrom and mockGetAuthContext are now initialized via vi.hoisted() instead of bare const declarations, which prevents the TDZ error that was blocking the four pagination regression tests from running.
  • No test logic, assertions, or route code was changed; this is purely a test infrastructure correction.

Confidence Score: 5/5

Safe to merge — the change is a two-line test infrastructure fix with no impact on production code.

The route implementation is untouched; only mock initialization in the test file changed. The vi.hoisted() pattern is the correct Vitest-recommended fix for this exact class of problem, and the four pagination tests now run with the same assertions as before.

No files require special attention.

Important Files Changed

Filename Overview
src/app/api/webhooks/[id]/deliveries/route.test.ts Two mock declarations replaced with vi.hoisted() to resolve Vitest TDZ issue; all four pagination tests are correctly exercised with no logic changes.

Sequence Diagram

sequenceDiagram
    participant Vitest as Vitest Runner
    participant Hoist as vi.hoisted()
    participant Mock as vi.mock()
    participant Test as Test Suite

    Note over Vitest: Module load / hoist phase
    Vitest->>Hoist: "Execute vi.hoisted(() => ({ mockFrom, mockGetAuthContext }))"
    Hoist-->>Vitest: mockFrom, mockGetAuthContext initialised
    Vitest->>Mock: "Execute vi.mock("@/lib/auth/get-user", factory)"
    Note over Mock: Factory safely references mockGetAuthContext (no TDZ)
    Mock-->>Vitest: Module stubbed

    Note over Vitest: Test execution phase
    Vitest->>Test: beforeEach — mockGetAuthContext.mockResolvedValue(...)
    Test->>Test: GET() called with NextRequest
    Test->>Mock: getAuthContext() returns user and supabase with mockFrom
    Test->>Test: supabase.from("webhooks").select.eq.single returns webhook data
    Test->>Test: supabase.from("webhook_deliveries")...range returns deliveries and count
    Test-->>Vitest: Assertions on res.status, range args, json.pagination
Loading

Reviews (1): Last reviewed commit: "test(webhooks): hoist delivery route moc..." | Re-trigger Greptile

@ralyodio ralyodio merged commit 0067d83 into profullstack:master Jun 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants